Skip to content

feat(sentry): mulai Sentry backend sebelum Express dan aktifkan tracing browser - #6

Merged
ronalandroid merged 1 commit into
mainfrom
feat/sentry-setup
Nov 22, 2026
Merged

ronalandroid merged 1 commit into
mainfrom
feat/sentry-setup

Conversation

@ronalandroid

Copy link
Copy Markdown
Owner

Ringkasan

Menyambungkan KaffePOS ke project Sentry baru (kaffe-pos/kaffepos-web dan kaffe-pos/kaffepos-api) dan memperbaiki tracing backend yang selama ini tidak merekam apa pun.

Yang berubah

  • backend/src/instrument.ts sekarang jadi import pertama di backend/src/index.ts. Build backend memakai CommonJS, jadi urutan import adalah urutan load. Sebelumnya initBackendErrorTracking() dipanggil setelah express dimuat: error tetap masuk lewat error handler, tapi instrumentasi OpenTelemetry tidak sempat memasang hook ke express, http, dan pg, sehingga tracing kosong.
  • src/lib/errorTracking.ts: saat VITE_SENTRY_TRACES_SAMPLE_RATE > 0, web memakai browserTracingIntegration() dan meneruskan trace ke api.kaffepos.my.id (tracePropagationTargets), sehingga satu request terlihat dari web sampai backend.

Catatan untuk reviewer

  • CORS backend memantulkan header yang diminta, jadi sentry-trace dan baggage lolos preflight. Sudah dicek dengan preflight sungguhan ke API live: 204 dengan header itu diizinkan.
  • sendDefaultPii tetap mati. SDK tetap di versi 10 (@sentry/react 10.51, @sentry/node 10.62); upgrade major ke 11 bisa menyusul.
  • Env sudah terpasang di Coolify: SENTRY_DSN, SENTRY_ENVIRONMENT=staging, dan SENTRY_TRACES_SAMPLE_RATE=0.1 (API, runtime); VITE_SENTRY_DSN dan VITE_SENTRY_TRACES_SAMPLE_RATE=0.1 (Web, build-time). Error dari production sudah masuk sebelum PR ini; tracing backend baru jalan setelah PR ini di-merge dan di-deploy.

Tes

  • npm run check: lint, typecheck, 454 tes, build web dan backend: lolos
  • Lokal dengan DSN asli: error tes KAFFEPOS-API-1 dan KAFFEPOS-WEB-1 masuk, begitu juga trace POST /api/auth/demo-login dan page load /
  • Live: error dari kaffepos.my.id masuk sebagai KAFFEPOS-WEB-2; system-status melaporkan backendErrorTracking: true

🤖 Generated with Claude Code

…tracing

- backend/src/instrument.ts is now the first import in index.ts, so Sentry
  initializes before express, http and pg are required. Before this, errors
  reached Sentry through the error handler but request tracing recorded
  nothing because the instrumentation loaded after express.
- The web app adds browserTracingIntegration and propagates traces to
  api.kaffepos.my.id when VITE_SENTRY_TRACES_SAMPLE_RATE > 0. The backend's
  CORS reflects requested headers, so sentry-trace and baggage pass preflight
  (checked against the live API).

Verified with the new Sentry projects kaffe-pos/kaffepos-api and
kaffe-pos/kaffepos-web: test errors KAFFEPOS-API-1 and KAFFEPOS-WEB-1 and a
trace from each arrived.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ronalandroid
ronalandroid merged commit 5f98db8 into main Nov 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant